package com.cdc.guidepages.ScrollView;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.LinearLayout;

import com.cdc.guidepages.MainActivity;
import com.cdc.guidepages.R;

public class MyScrollViewActivity extends AppCompatActivity {
    
    private MyScrollView myScrollView;

    private LinearLayout ll_anim;
    private Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_scroll_view);
        
        initView();
    }

    private void initView() {
        myScrollView=findViewById(R.id.myScrollView);
        ll_anim=findViewById(R.id.ll_anim);
        btn=findViewById(R.id.btn);

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MyScrollViewActivity.this, MainActivity.class));
            }
        });

        myScrollView.setOnSrollChangedListener(new MyScrollView.OnSrollChangedListener() {
            @Override
            public void onScrollChange(int top, int oldTop) {
                if(top>oldTop){//上划操作
                    Animation animation= AnimationUtils.loadAnimation(MyScrollViewActivity.this,R.anim.show);
                    ll_anim.setVisibility(View.VISIBLE);
                    ll_anim.startAnimation(animation);
                }else{
                    //下划操作
                    Animation animation= AnimationUtils.loadAnimation(MyScrollViewActivity.this,R.anim.close);
                    ll_anim.setVisibility(View.INVISIBLE);
                    ll_anim.startAnimation(animation);
                }
            }
        });

    }
}
